<template>
  <body class="bacstyle">

    <div class="loginBox">

      <h1 class="logo">港口堆存费管理系统</h1>

      <el-form ref="loginFormRef" :model="loginForm" :rules="loginFormRules" label-width="0px" class="login_form">

        <el-form-item prop = "username">
          <el-input v-model="loginForm.username" prefix-icon="el-icon-user"></el-input>
        </el-form-item>

        <el-form-item prop = "password">
          <el-input v-model="loginForm.password" prefix-icon="el-icon-lock" type="password"></el-input>
        </el-form-item>

        <el-form-item class="btns">
          <el-button type="primary"  @click="login" round>登录</el-button>
          <el-button type="info" @click="resetLoginForm" round>重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </body>
</template>

<script>
export default {
  data() {
    return {
      loginForm: {
        username: '',
        password: ''
      },
      loginFormRules: {
        username: [
          { required: true, message: '请输入用户名称', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    resetLoginForm() {
      this.$refs.loginFormRef.resetFields()
    },
    login() {
      this.$refs.loginFormRef.validate(valid => {
        if (!valid) return
        // const result = this.$http.post('login', this.loginForm)
        // console.log(result)
        if (this.loginForm.username === 'admin' && this.loginForm.password === '123456') {
          return this.$router.push('/home')
        } else {
          return this.$message.error('登陆失败')
        }
      })
    }
  }
}

</script>

<style lang="less" scoped>
  .bacstyle{
    background-color: #f7f3f3;
    height: 100%;
  }
  .loginBox{
    background-color: #bbdfe8;
    height: 300px;
    width: 450px;
    border-radius: 5px;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%,-50%);
    box-shadow: 0 0 30px #7bafeb;
  }
  .btns{
    display: flex;
    justify-content: flex-end;
  }
  .login_form{
    position: absolute;
    bottom: 0;
    width: 100%;
    padding: 0 30px;
    box-sizing: border-box;
  }
  .logo{
    color: #083b87;
    border-radius: 5px;
    position: absolute;
    left: 30%;
    top: 20%;
    transform: translate(-20%,-60%);
    padding: 10px 10px 10px;
    box-sizing: border-box;
    margin: 0px auto 40px auto;
    text-align: center;

  }
</style>
